package geez.widget;

import com.google.gwt.user.client.ui.SuggestOracle;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class GSuggestOracle extends SuggestOracle {
    private List<String> items;

    public GSuggestOracle(List<String> items) {
        this.items = items;
    }

    public GSuggestOracle(String... items) {
        this(Arrays.asList(items));
    }

    public void requestSuggestions(final Request request, Callback callback) {
        Response response = new Response();
        ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>();
        for (final String item : items) {
            suggestions.add(new Suggestion() {
                public String getDisplayString() {
                    return item;
                }

                public String getReplacementString() {
                    return item;
                }
            });
        }
        response.setSuggestions(suggestions);
        callback.onSuggestionsReady(request, response);
    }
}
